package org.springMvc.controller.Impl;

import org.springMvc.controller.TeacherController;
import org.springMvc.domain.Teacher;
import org.springMvc.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller("teacherController")
@RequestMapping("/teacher")
public class TeacherControllerImpl implements TeacherController {

    @Autowired
    private TeacherService teacherService;

    @Override
    public void insert(Teacher teacher) {
        teacherService.saveTeacher(teacher);
    }

    @Override
    public void delete(Integer id) {
        teacherService.deleteTeacher(id);
    }

    @Override
    public void update(Teacher teacher) {
        teacherService.updateTeacher(teacher);
    }

    @RequestMapping("/")
    public String toIndex() {
        return "index";
    }

    @Override
    @RequestMapping("/findAll")
    @ResponseBody
    public String findAll() {
        List<Teacher> all = teacherService.findAll();
        return "{'info':'running'}";
    }

    @Override
    public Teacher findOne(Integer id) {
        return teacherService.findOne(id);
    }
}
